import 'package:bot_toast/bot_toast.dart';
import 'package:demo/config/pages.dart';
import 'package:demo/global_cubit.dart';
import 'package:demo/pages/ble/ble.dart';
import 'package:demo/pages/chat/chat.dart';
import 'package:demo/pages/home/home.dart';
import 'package:demo/pages/home_editor/home_editor.dart';
import 'package:demo/pages/login.dart';
import 'package:demo/pages/markdown_editor/markdown_editor.dart';
import 'package:demo/pages/markdown_editor_web/markdown_editor_web.dart';
import 'package:demo/pages/scan.dart';
import 'package:demo/pages/setting.dart';
import 'package:demo/pages/pdf/pdf.dart';
import 'package:demo/pages/tian_shu/tian_shu.dart';
import 'package:demo/pages/web.dart';
import 'package:flutter/material.dart';

final GlobalCubit globalCubit = GlobalCubit();

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await globalCubit.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    var initRoute = (globalCubit.state.user.email == "" && globalCubit.state.user.phone == "") ? "login" : "home";
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.transparent),
        useMaterial3: true,
      ),
      builder: BotToastInit(),
      navigatorObservers: [BotToastNavigatorObserver()],
      routes: {
        "home": (context) => const HomePage(),
        "web": (context) => const WebPage(),
        "login": (context) => const LoginPage(),
        "setting": (context) => const SettingPage(),
        "scan": (context) => const ScanPage(),
        "editor": (context) => const HomeEditorPage(),
        "markdown_editor": (context) => const MarkdownEditorPage(),
        "markdown_editor_web": (context) => const MarkdownEditorWebPage(),
        "chat": (context) => const ChatPage(),
        "pdf": (context) => const PdfPage(),
        "ble": (context) => const BlePage(),
        Pages.TianShu.toString(): (context) => const TianShuPage(),
      },
      initialRoute: initRoute,
    );
  }
}
